#ifndef SWP_ABSTRACT_LINKED_DOCUMENT_H
#define SWP_ABSTRACT_LINKED_DOCUMENT_H

#include <ilinkeddocument.h>
#include <mimetype.h>

#include <QtCore/QList>

namespace swp
{

class SwpAbstractLinkedDocument : public core::ILinkedDocument
{
    Q_OBJECT

public:
    SwpAbstractLinkedDocument(const QString& name, const core::MimeType& mimeType,
        const QSharedPointer<core::IContainerDocument>& container,
        bool isFuture);
    ~SwpAbstractLinkedDocument();

    void setValid(bool valid);
    virtual bool isValid() const;

    bool isFuture() const;

    virtual bool isLinked() const;
    virtual bool isContainer() const;

    bool isDirty() const;
    QString name() const;

    core::MimeType mimeType() const;

    QSharedPointer<core::IContainerDocument> container() const;

    void setDirty(bool dirty = true);
    void setFuture(bool future = true);
    void setContainer(
        const QSharedPointer<core::IContainerDocument>& container);

    void rename(const QString& name);

    core::IDocumentData* data() const;

    // ILinkedDocument
    QList<QSharedPointer<IDocument> > links() const;

    void addLink(const QSharedPointer<core::IDocument>& document,
        bool projectIsOpening = false);
    void removeLink(const QSharedPointer<core::IDocument>& document);

    void refreshLinkedModels();

protected:
    virtual void linksUpdated(bool projectIsOpening);

private:
    void openLinksToMemory();
    void closeOpenedLinks();

private slots:
    void makeDirty();

protected:
    bool m_valid;
    QString m_name;
    core::MimeType m_mimeType;
    bool m_isDirty;
    bool m_isFuture;
    QSharedPointer<core::IContainerDocument> m_container;
    core::IDocumentData* m_data;
    QList<QSharedPointer<core::IDocument> > m_links;
    QList<QSharedPointer<core::IDocument> > m_openedLinks;
};

} // namespace swp

#endif
